//
//  TaskManagerDetailCell.m
//  LogisticsSupplier
//
//  Created by 吕晶 on 2021/3/22.
//  Copyright © 2021 吕晶. All rights reserved.
//

#import "TaskManagerDetailCell.h"

@interface TaskManagerDetailCell ()

@property (nonatomic, strong) UIView *bgView;
@property (nonatomic, strong) UILabel *noTitleLab;//单号
@property (nonatomic, strong) UILabel *noLab;
@property (nonatomic, strong) UIButton *detailBtn;

@property (nonatomic, strong) UIView *timeLimitView;
@property (nonatomic, strong) UILabel *timeLimitTitleLab;
@property (nonatomic, strong) UILabel *timeLimitLab;

@property (nonatomic, strong) UIView *addressBGView;
@property (nonatomic, strong) UILabel *fromAddLab;
@property (nonatomic, strong) UIImageView *statusImgView;
@property (nonatomic, strong) UILabel *toAddLab;

@property (nonatomic, strong) UIImageView *faImgView;
@property (nonatomic, strong) UILabel *faAddressLab;
@property (nonatomic, strong) UILabel *faDetailLab;
@property (nonatomic, strong) UILabel *faInfoLab;
@property (nonatomic, strong) UILabel *marginLine;
@property (nonatomic, strong) UIImageView *shouImgView;
@property (nonatomic, strong) UILabel *shAddressLab;
@property (nonatomic, strong) UILabel *shDetailLab;
@property (nonatomic, strong) UILabel *shInfoLab;
@property (nonatomic, strong) UILabel *linkLine;
@property (nonatomic, strong) UILabel *marginLine2;

@property (nonatomic, strong) UILabel *goodPieceTitleLab;
@property (nonatomic, strong) UILabel *goodPieceLab;
@property (nonatomic, strong) UILabel *weightTitleLab;
@property (nonatomic, strong) UILabel *weightLab;
@property (nonatomic, strong) UILabel *volumeTitleLab;
@property (nonatomic, strong) UILabel *volumeLab;
@property (nonatomic, strong) UILabel *timeTitleLab;
@property (nonatomic, strong) UILabel *timeLab;

@property (nonatomic, strong) UIButton *erWeiMaBtn;//二维码
@property (nonatomic, strong) UIButton *sureDaoDaBtn;//确认到达
@property (nonatomic, strong) UIButton *chaoChuFanWeiBtn;//超出范围
@property (nonatomic, strong) UIButton *yiChangShangBaoBtn;//异常上报
@property (nonatomic, strong) UIButton *dianHuoZhuangCheBtn;//点货装车
@property (nonatomic, strong) UIButton *yiJianZhuangCheBtn;//一键装车
@property (nonatomic, strong) UIButton *boHuiReasonBtn;//驳回原因
@property (nonatomic, strong) UIButton *waitSureBtn;//待发货方装车确认

@end

@implementation TaskManagerDetailCell

+ (instancetype)TaskManagerDetailCellWithTableView:(UITableView *)tableView {
    static NSString *cellID = @"TaskManagerDetailCell";
    TaskManagerDetailCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
    if (cell == nil) {
        cell = [[TaskManagerDetailCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
    }
    return cell;
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        self.backgroundColor = Color_backgroundColor;
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        
        self.bgView = [UIView new];
        self.bgView.backgroundColor = HexColor(0xffffff);
        self.bgView.layer.masksToBounds = YES;
        self.bgView.layer.cornerRadius = 6;
        [self.contentView addSubview:self.bgView];
        
        self.noTitleLab = [UILabel new];
        self.noTitleLab.textColor = HexColor(0x9C9DB3);
        self.noTitleLab.font = BoldFontOfSize(16);
        [self.bgView addSubview:self.noTitleLab];
        
        self.noLab = [UILabel new];
        self.noLab.textColor = HexColor(0x2B2C44);
        self.noLab.font = BoldFontOfSize(16);
        [self.bgView addSubview:self.noLab];
        
        self.detailBtn = [UIButton new];
        [self.detailBtn setTitleColor:Color_ThemeColor forState:0];
        self.detailBtn.titleLabel.font = BoldFontOfSize(14);
        [self.detailBtn addTarget:self action:@selector(detailClick) forControlEvents:UIControlEventTouchUpInside];
        [self.bgView addSubview:self.detailBtn];
        
        self.addressBGView = [UIView new];
        self.addressBGView.backgroundColor = HexColor(0xF7F7FA);
        self.addressBGView.layer.cornerRadius = 2;
        [self.bgView addSubview:self.addressBGView];
        
        self.fromAddLab = [UILabel new];
        self.fromAddLab.textColor = HexColor(0x2B2C44);
        self.fromAddLab.font = BoldFontOfSize(20);
        self.fromAddLab.textAlignment = NSTextAlignmentCenter;
        [self.addressBGView addSubview:self.fromAddLab];
        
        self.statusImgView = [UIImageView new];
        [self.addressBGView addSubview:self.statusImgView];
        
        self.toAddLab = [UILabel new];
        self.toAddLab.textColor = HexColor(0x2B2C44);
        self.toAddLab.font = BoldFontOfSize(20);
        self.toAddLab.textAlignment = NSTextAlignmentCenter;
        [self.addressBGView addSubview:self.toAddLab];

        self.faImgView = [UIImageView new];
        self.faImgView.image = [UIImage imageNamed:@"icon_add_ti"];
        [self.bgView addSubview:self.faImgView];
        
        self.faAddressLab = [UILabel new];
        self.faAddressLab.textColor = HexColor(0x2B2C44);
        self.faAddressLab.font = BoldFontOfSize(16);
        self.faAddressLab.numberOfLines = 0;
        [self.bgView addSubview:self.faAddressLab];
        
        self.faDetailLab = [UILabel new];
        self.faDetailLab.textColor = HexColor(0x2B2C44);
        self.faDetailLab.font = BoldFontOfSize(14);
        self.faDetailLab.numberOfLines = 0;
        [self.bgView addSubview:self.faDetailLab];
        
        self.faInfoLab = [UILabel new];
        self.faInfoLab.textColor = HexColor(0x585974);
        self.faInfoLab.font = BoldFontOfSize(12);
        self.faInfoLab.numberOfLines = 0;
        [self.bgView addSubview:self.faInfoLab];
        
        self.shouImgView = [UIImageView new];
        self.shouImgView.image = [UIImage imageNamed:@"icon_add_song"];
        [self.bgView addSubview:self.shouImgView];
        
        self.shAddressLab = [UILabel new];
        self.shAddressLab.textColor = HexColor(0x2B2C44);
        self.shAddressLab.font = BoldFontOfSize(16);
        self.shAddressLab.numberOfLines = 0;
        [self.bgView addSubview:self.shAddressLab];
        
        self.shDetailLab = [UILabel new];
        self.shDetailLab.textColor = HexColor(0x2B2C44);
        self.shDetailLab.font = BoldFontOfSize(14);
        self.shDetailLab.numberOfLines = 0;
        [self.bgView addSubview:self.shDetailLab];
        
        self.shInfoLab = [UILabel new];
        self.shInfoLab.textColor = HexColor(0x585974);
        self.shInfoLab.font = BoldFontOfSize(12);
        self.shInfoLab.numberOfLines = 0;
        [self.bgView addSubview:self.shInfoLab];
        
        self.marginLine = [UILabel new];
        self.marginLine.backgroundColor = Color_backgroundColor;
        [self.bgView addSubview:self.marginLine];
        
        self.linkLine = [UILabel new];
        self.linkLine.backgroundColor = HexColorA(0x3D68EB, 0.2);
        [self.bgView addSubview:self.linkLine];
        
        self.marginLine2 = [UILabel new];
        self.marginLine2.backgroundColor = Color_backgroundColor;
        [self.bgView addSubview:self.marginLine2];
        
        self.goodPieceTitleLab = [UILabel new];
        self.goodPieceTitleLab.textColor = HexColor(0x9C9DB3);
        self.goodPieceTitleLab.font = [UIFont systemFontOfSize:12];
        [self.bgView addSubview:self.goodPieceTitleLab];
        
        self.goodPieceLab = [UILabel new];
        self.goodPieceLab.textColor = HexColor(0x2B2C44);
        self.goodPieceLab.font = [UIFont systemFontOfSize:12];
        [self.bgView addSubview:self.goodPieceLab];
        
        self.weightTitleLab = [UILabel new];
        self.weightTitleLab.textColor = HexColor(0x9C9DB3);
        self.weightTitleLab.font = [UIFont systemFontOfSize:12];
        [self.bgView addSubview:self.weightTitleLab];
        
        self.weightLab = [UILabel new];
        self.weightLab.textColor = HexColor(0x2B2C44);
        self.weightLab.font = [UIFont systemFontOfSize:12];
        [self.bgView addSubview:self.weightLab];
        
        self.volumeTitleLab = [UILabel new];
        self.volumeTitleLab.textColor = HexColor(0x9C9DB3);
        self.volumeTitleLab.font = [UIFont systemFontOfSize:12];
        [self.bgView addSubview:self.volumeTitleLab];
        
        self.volumeLab = [UILabel new];
        self.volumeLab.textColor = HexColor(0x2B2C44);
        self.volumeLab.font = [UIFont systemFontOfSize:12];
        [self.bgView addSubview:self.volumeLab];
        
        self.timeTitleLab = [UILabel new];
        self.timeTitleLab.textColor = HexColor(0x9C9DB3);
        self.timeTitleLab.font = [UIFont systemFontOfSize:12];
        [self.bgView addSubview:self.timeTitleLab];
        
        self.timeLab = [UILabel new];
        self.timeLab.textColor = HexColor(0x2B2C44);
        self.timeLab.font = [UIFont systemFontOfSize:12];
        [self.bgView addSubview:self.timeLab];
        
        self.timeLimitView = [UIView new];
        self.timeLimitView.backgroundColor = HexColorA(0xF35959, 0.1);
        self.timeLimitView.layer.masksToBounds = YES;
        self.timeLimitView.layer.cornerRadius = 2;
        [self.bgView addSubview:self.timeLimitView];
        
        self.timeLimitTitleLab = [UILabel new];
        self.timeLimitTitleLab.textColor = HexColor(0x2B2C44);
        self.timeLimitTitleLab.font = [UIFont systemFontOfSize:12];
        [self.timeLimitView addSubview:self.timeLimitTitleLab];
        
        self.timeLimitLab = [UILabel new];
        self.timeLimitLab.textColor = HexColor(0xF35959);
        self.timeLimitLab.font = BoldFontOfSize(14);
        [self.timeLimitView addSubview:self.timeLimitLab];
        
//        self.erWeiMaBtn = [UIButton new];
//        [self.erWeiMaBtn setTitle:@"二维码" forState:0];
//        [self.erWeiMaBtn setTitleColor:HexColor(0x585974) forState:0];
//        self.erWeiMaBtn.titleLabel.font = BoldFontOfSize(14);
//        self.erWeiMaBtn.layer.masksToBounds = YES;
//        self.erWeiMaBtn.layer.cornerRadius = 16;
//        self.erWeiMaBtn.backgroundColor = HexColor(0xffffff);
//        self.erWeiMaBtn.layer.borderColor = HexColor(0xDBDCE6).CGColor;
//        self.erWeiMaBtn.layer.borderWidth = 1;
//        [self.erWeiMaBtn addTarget:self action:@selector(erWeiMaClick) forControlEvents:UIControlEventTouchUpInside];
//        [self.bgView addSubview:self.erWeiMaBtn];
        
        self.sureDaoDaBtn = [UIButton new];
        [self.sureDaoDaBtn setTitle:@"确认到达" forState:0];
        [self.sureDaoDaBtn setTitleColor:HexColor(0xffffff) forState:0];
        self.sureDaoDaBtn.titleLabel.font = BoldFontOfSize(14);
        self.sureDaoDaBtn.layer.masksToBounds = YES;
        self.sureDaoDaBtn.layer.cornerRadius = 16;
        self.sureDaoDaBtn.backgroundColor = Color_ThemeColor;
        [self.sureDaoDaBtn addTarget:self action:@selector(sureDaoDaClick) forControlEvents:UIControlEventTouchUpInside];
        [self.bgView addSubview:self.sureDaoDaBtn];
        
        self.chaoChuFanWeiBtn = [UIButton new];
        [self.chaoChuFanWeiBtn setTitle:@"不在目的地位置范围内" forState:0];
        [self.chaoChuFanWeiBtn setTitleColor:HexColor(0xffffff) forState:0];
        self.chaoChuFanWeiBtn.titleLabel.font = BoldFontOfSize(14);
        self.chaoChuFanWeiBtn.layer.masksToBounds = YES;
        self.chaoChuFanWeiBtn.layer.cornerRadius = 16;
        self.chaoChuFanWeiBtn.backgroundColor = HexColor(0xDBDCE6);
        self.chaoChuFanWeiBtn.userInteractionEnabled = NO;
        [self.bgView addSubview:self.chaoChuFanWeiBtn];
        
        self.yiChangShangBaoBtn = [UIButton new];
        [self.yiChangShangBaoBtn setTitle:@"状态上报" forState:0];
        [self.yiChangShangBaoBtn setTitleColor:HexColor(0xF35959) forState:0];
        self.yiChangShangBaoBtn.titleLabel.font = BoldFontOfSize(14);
        self.yiChangShangBaoBtn.layer.masksToBounds = YES;
        self.yiChangShangBaoBtn.layer.cornerRadius = 16;
        self.yiChangShangBaoBtn.backgroundColor = HexColorA(0xF35959, 0.1);
        [self.yiChangShangBaoBtn addTarget:self action:@selector(yiChangShangBaoClick) forControlEvents:UIControlEventTouchUpInside];
        [self.bgView addSubview:self.yiChangShangBaoBtn];
        
        self.dianHuoZhuangCheBtn = [UIButton new];
        [self.dianHuoZhuangCheBtn setTitle:@"点货装车" forState:0];
        [self.dianHuoZhuangCheBtn setTitleColor:HexColor(0xffffff) forState:0];
        self.dianHuoZhuangCheBtn.titleLabel.font = BoldFontOfSize(14);
        self.dianHuoZhuangCheBtn.layer.masksToBounds = YES;
        self.dianHuoZhuangCheBtn.layer.cornerRadius = 16;
        self.dianHuoZhuangCheBtn.backgroundColor = Color_ThemeColor;
        [self.dianHuoZhuangCheBtn addTarget:self action:@selector(dianHuoZhuangCheClick) forControlEvents:UIControlEventTouchUpInside];
        [self.bgView addSubview:self.dianHuoZhuangCheBtn];
        
        self.yiJianZhuangCheBtn = [UIButton new];
        [self.yiJianZhuangCheBtn setTitle:@"一键装车" forState:0];
        [self.yiJianZhuangCheBtn setTitleColor:HexColor(0xffffff) forState:0];
        self.yiJianZhuangCheBtn.titleLabel.font = BoldFontOfSize(14);
        self.yiJianZhuangCheBtn.layer.masksToBounds = YES;
        self.yiJianZhuangCheBtn.layer.cornerRadius = 16;
        self.yiJianZhuangCheBtn.backgroundColor = Color_ThemeColor;
        [self.yiJianZhuangCheBtn addTarget:self action:@selector(yiJianZhuangCheClick) forControlEvents:UIControlEventTouchUpInside];
        [self.bgView addSubview:self.yiJianZhuangCheBtn];
        
        self.boHuiReasonBtn = [UIButton new];
        [self.boHuiReasonBtn setTitle:@"驳回原因" forState:0];
        [self.boHuiReasonBtn setTitleColor:HexColor(0xF35959) forState:0];
        self.boHuiReasonBtn.titleLabel.font = BoldFontOfSize(14);
        self.boHuiReasonBtn.layer.masksToBounds = YES;
        self.boHuiReasonBtn.layer.cornerRadius = 16;
        self.boHuiReasonBtn.backgroundColor = HexColorA(0xF35959, 0.1);
        [self.boHuiReasonBtn addTarget:self action:@selector(boHuiReasonClick) forControlEvents:UIControlEventTouchUpInside];
        [self.bgView addSubview:self.boHuiReasonBtn];
        
        self.waitSureBtn = [UIButton new];
        [self.waitSureBtn setTitle:@"待发货方装车确认" forState:0];
        [self.waitSureBtn setTitleColor:HexColor(0xFBA962) forState:0];
        self.waitSureBtn.titleLabel.font = BoldFontOfSize(14);
        self.waitSureBtn.layer.masksToBounds = YES;
        self.waitSureBtn.layer.cornerRadius = 16;
        self.waitSureBtn.backgroundColor = HexColor(0xffffff);
        self.waitSureBtn.userInteractionEnabled = NO;
        [self.bgView addSubview:self.waitSureBtn];
    }
    return self;
}

- (void)erWeiMaClick {
    if (self.erWeiMaBlock) {
        self.erWeiMaBlock();
    }
}

- (void)sureDaoDaClick {
    if (self.sureDaoDaBlock) {
        self.sureDaoDaBlock();
    }
}

- (void)yiChangShangBaoClick {
    if (self.yiChangShangBaoBlock) {
        self.yiChangShangBaoBlock();
    }
}

- (void)dianHuoZhuangCheClick {
    if (self.dianHuoZhuangCheBlock) {
        self.dianHuoZhuangCheBlock();
    }
}

- (void)yiJianZhuangCheClick {
    if (self.yiJianZhuangCheBlock) {
        self.yiJianZhuangCheBlock();
    }
}

- (void)boHuiReasonClick {
    if (self.boHuiReasonBlock) {
        self.boHuiReasonBlock();
    }
}

-(void)setModel:(TaskManagerDetailOrderModel *)model {
    _model = model;
    [self configUI];
}

- (void)detailClick {
    if (self.detailBlock) {
        self.detailBlock();
    }
}

- (void)configUI {
    self.bgView.nim_left = 15;
    self.bgView.nim_top = 0;
    self.bgView.nim_width = ScreenW - 30;
    
    self.noTitleLab.text = @"单号：";
    self.noTitleLab.nim_left = 10;
    self.noTitleLab.nim_top = 15;
    [self.noTitleLab sizeToFit];
    
    self.noLab.text = self.model.serial_num;
    self.noLab.nim_left = self.noTitleLab.nim_right;
    [self.noLab sizeToFit];
    self.noLab.nim_centerY = self.noTitleLab.nim_centerY;
    
    self.detailBtn.nim_width = 60;
    self.detailBtn.nim_height = 20;
    self.detailBtn.nim_left = self.bgView.nim_width - 10 - self.detailBtn.nim_width;
    self.detailBtn.nim_centerY = self.noTitleLab.nim_centerY;
    [self.detailBtn setTitle:@"详情" forState:0];
    [self.detailBtn setImage:[UIImage imageNamed:@"icon_detail_arrow"] forState:0];
    self.detailBtn.imageEdgeInsets = UIEdgeInsetsMake(0, 45, 0, 0);
    self.detailBtn.titleEdgeInsets = UIEdgeInsetsMake(0, -20, 0, 0);
    
    self.addressBGView.frame = CGRectMake(10, self.noTitleLab.nim_bottom + 10, self.bgView.nim_width - 20, 68);
    
    self.statusImgView.nim_width = 59;
    self.statusImgView.nim_height = 10;
    self.statusImgView.nim_left = (self.addressBGView.nim_width - self.statusImgView.nim_width) * 0.5;
    self.statusImgView.nim_centerY = self.addressBGView.nim_height * 0.5;
    [self.statusImgView setImage:[UIImage imageNamed:@"operationbill_status"]];
    
    self.fromAddLab.nim_left = 10;
    self.fromAddLab.text = self.model.s_city;
    [self.fromAddLab sizeToFit];
    self.fromAddLab.nim_width = self.statusImgView.nim_left - 20;
    self.fromAddLab.nim_centerY = self.statusImgView.nim_centerY;
    
    self.toAddLab.nim_left = 10 + self.statusImgView.nim_right;
    self.toAddLab.text = self.model.r_city;
    [self.toAddLab sizeToFit];
    self.toAddLab.nim_width = self.addressBGView.nim_width - 10 - self.toAddLab.nim_left;
    self.toAddLab.nim_centerY = self.statusImgView.nim_centerY;
    
    self.faAddressLab.nim_left = 59;
    self.faAddressLab.nim_top = 15 + self.addressBGView.nim_bottom;
    self.faAddressLab.nim_width = self.bgView.nim_width - 10 - self.faAddressLab.nim_left;
    self.faAddressLab.text = [NSString stringWithFormat:@"%@%@%@",self.model.s_province,self.model.s_city,self.model.s_town];
    [self.faAddressLab sizeToFit];
    self.faAddressLab.nim_width = self.bgView.nim_width - 10 - self.faAddressLab.nim_left;
    
    self.faDetailLab.nim_width = self.faAddressLab.nim_width;
    self.faDetailLab.text = self.model.s_info;
    self.faDetailLab.nim_left = self.faAddressLab.nim_left;
    self.faDetailLab.nim_top = self.faAddressLab.nim_bottom + 5;
    [self.faDetailLab sizeToFit];
    self.faDetailLab.nim_width = self.faAddressLab.nim_width;
    
    self.faInfoLab.nim_width = self.faDetailLab.nim_width;
    self.faInfoLab.text = [NSString stringWithFormat:@"%@ %@",self.model.s_tel_name,self.model.s_phone];
    self.faInfoLab.nim_left = self.faDetailLab.nim_left;
    self.faInfoLab.nim_top = self.faDetailLab.nim_bottom + 10;
    [self.faInfoLab sizeToFit];
    self.faInfoLab.nim_width = self.faDetailLab.nim_width;
    
    
    self.marginLine.nim_left = self.faAddressLab.nim_left - 5;
    self.marginLine.nim_top = self.faInfoLab.nim_bottom + 10;
    self.marginLine.nim_width = self.bgView.nim_width - self.marginLine.nim_left;
    self.marginLine.nim_height = 1;

    self.shAddressLab.nim_left = 59;
    self.shAddressLab.nim_top = 10 + self.marginLine.nim_bottom;
    self.shAddressLab.nim_width = self.bgView.nim_width - 10 - self.shAddressLab.nim_left;
    self.shAddressLab.text = [NSString stringWithFormat:@"%@%@%@",self.model.r_province,self.model.r_city,self.model.r_town];
    [self.shAddressLab sizeToFit];
    self.shAddressLab.nim_width = self.bgView.nim_width - 10 - self.shAddressLab.nim_left;
    
    self.shDetailLab.nim_width = self.shAddressLab.nim_width;
    self.shDetailLab.text = self.model.r_info;
    self.shDetailLab.nim_left = self.shAddressLab.nim_left;
    self.shDetailLab.nim_top = self.shAddressLab.nim_bottom + 5;
    [self.shDetailLab sizeToFit];
    self.shDetailLab.nim_width = self.shAddressLab.nim_width;
    
    self.shInfoLab.nim_width = self.shDetailLab.nim_width;
    self.shInfoLab.text = [NSString stringWithFormat:@"%@ %@",self.model.r_tel_name,self.model.r_phone];
    self.shInfoLab.nim_left = self.shDetailLab.nim_left;
    self.shInfoLab.nim_top = self.shDetailLab.nim_bottom + 10;
    [self.shInfoLab sizeToFit];
    self.shInfoLab.nim_width = self.shDetailLab.nim_width;
    
    self.faImgView.nim_width = 22;
    self.faImgView.nim_height = 22;
    self.faImgView.nim_left = 20;
    self.faImgView.nim_top = (self.marginLine.nim_top - self.addressBGView.nim_bottom - self.faImgView.nim_width) * 0.5 + self.addressBGView.nim_bottom;
    
    self.shouImgView.nim_width = 22;
    self.shouImgView.nim_height = 22;
    self.shouImgView.nim_left = 20;
    self.shouImgView.nim_top = self.shInfoLab.nim_bottom + 15 - (self.shInfoLab.nim_bottom + 15 - self.marginLine.nim_bottom - self.shouImgView.nim_height) * 0.5 - self.shouImgView.nim_height;
    
    self.linkLine.nim_width = 2;
    self.linkLine.nim_top = self.faImgView.nim_bottom + 3;
    self.linkLine.nim_height = self.shouImgView.nim_top - 3 - self.linkLine.nim_top;
    self.linkLine.nim_centerX = self.faImgView.nim_centerX;
    
    self.marginLine2.frame = CGRectMake(10, self.shInfoLab.nim_bottom + 15, self.bgView.nim_width - 10, 2);
    
    self.goodPieceTitleLab.text = @"货物件数：";
    [self.goodPieceTitleLab sizeToFit];
    self.goodPieceTitleLab.nim_left = 10;
    self.goodPieceTitleLab.nim_top = self.marginLine2.nim_bottom + 10;
    
    self.goodPieceLab.text = self.model.goodsJnum;
    [self.goodPieceLab sizeToFit];
    self.goodPieceLab.nim_left = self.goodPieceTitleLab.nim_right;
    self.goodPieceLab.nim_centerY = self.goodPieceTitleLab.nim_centerY;
    self.goodPieceLab.nim_width = self.bgView.nim_width - 10 - self.goodPieceLab.nim_left;
    
    self.weightTitleLab.text = @"货物重量：";
    [self.weightTitleLab sizeToFit];
    self.weightTitleLab.nim_left = 10;
    self.weightTitleLab.nim_top = self.goodPieceTitleLab.nim_bottom + 5;
    
    self.weightLab.text = [self.model.allWeight floatValue] ? [NSString stringWithFormat:@"%@KG",self.model.allWeight] : @"--KG";
    [self.weightLab sizeToFit];
    self.weightLab.nim_left = self.weightTitleLab.nim_right;
    self.weightLab.nim_centerY = self.weightTitleLab.nim_centerY;
    self.weightLab.nim_width = self.bgView.nim_width * 0.5 - self.weightLab.nim_left;
    
    self.volumeTitleLab.text = @"货物体积：";
    [self.volumeTitleLab sizeToFit];
    self.volumeTitleLab.nim_left = self.bgView.nim_width * 0.5;
    self.volumeTitleLab.nim_top = self.weightTitleLab.nim_top;
    
    self.volumeLab.text = [self.model.allVolume floatValue] ? [NSString stringWithFormat:@"%@m³",self.model.allVolume] : @"--m³";
    [self.volumeLab sizeToFit];
    self.volumeLab.nim_left = self.volumeTitleLab.nim_right;
    self.volumeLab.nim_centerY = self.volumeTitleLab.nim_centerY;
    self.volumeLab.nim_width = self.bgView.nim_width - 10 - self.volumeLab.nim_left;
    
    self.timeTitleLab.text = @"要求到达时间：";
    [self.timeTitleLab sizeToFit];
    self.timeTitleLab.nim_left = 10;
    self.timeTitleLab.nim_top = self.weightTitleLab.nim_bottom + 5;
    
    self.timeLab.text = self.model.arrivalTime;
    [self.timeLab sizeToFit];
    self.timeLab.nim_left = self.timeTitleLab.nim_right;
    self.timeLab.nim_centerY = self.timeTitleLab.nim_centerY;
    self.timeLab.nim_width = self.bgView.nim_width - 10 - self.timeTitleLab.nim_right;
    
    self.timeLimitView.frame = CGRectZero;
    self.timeLimitTitleLab.frame = CGRectZero;
    self.timeLimitLab.frame = CGRectZero;
    
    CGFloat addressTop = self.timeTitleLab.nim_bottom;
    if (self.model.is_dp_wa == 1) {
        if (self.model.status == 3 || self.model.status == 9 || self.model.status == 10) {
            //提单 驳回、已完成、作废时不显示倒计时
        }else {
            if (self.model.countdown > 0) {
                self.timeLimitView.frame = CGRectMake(self.noTitleLab.nim_left, addressTop + 10, self.bgView.nim_width - 2 * self.noTitleLab.nim_left, 33);
                self.timeLimitTitleLab.text = @"距要求到达时间仅剩";
                [self.timeLimitTitleLab sizeToFit];
                self.timeLimitTitleLab.nim_left = self.timeLimitView.nim_width * 0.5 - 15 - self.timeLimitTitleLab.nim_width;
                self.timeLimitTitleLab.nim_centerY = self.timeLimitView.nim_height * 0.5;
                NSInteger days = (int)(self.model.countdown/(3600*24));
                NSInteger hours = (int)((self.model.countdown-days*24*3600)/3600);
                NSInteger minute = (int)(self.model.countdown-days*24*3600-hours*3600)/60;
                NSInteger second = self.model.countdown - days*24*3600 - hours*3600 - minute*60;
                if (days) {
                    self.timeLimitLab.text = [NSString stringWithFormat:@"%ld天%02ld:%02ld:%02ld",(long)days,(long)hours,(long)minute,(long)second];
                }else if (hours) {
                    self.timeLimitLab.text = [NSString stringWithFormat:@"%02ld:%02ld:%02ld",(long)hours,(long)minute,(long)second];
                }else {
                    self.timeLimitLab.text = [NSString stringWithFormat:@"%02ld:%02ld",(long)minute,(long)second];
                }
                [self.timeLimitLab sizeToFit];
                self.timeLimitLab.nim_left = self.timeLimitView.nim_width * 0.5 - 5;
                self.timeLimitLab.nim_centerY = self.timeLimitView.nim_height * 0.5;
                
                addressTop = self.timeLimitView.nim_bottom;
            }else {
                self.timeLimitView.frame = CGRectMake(self.noTitleLab.nim_left, addressTop + 10, self.bgView.nim_width - 2 * self.noTitleLab.nim_left, 33);
                self.timeLimitTitleLab.text = @"距要求到达时间";
                [self.timeLimitTitleLab sizeToFit];
                self.timeLimitTitleLab.nim_left = self.timeLimitView.nim_width * 0.5 - 15 - self.timeLimitTitleLab.nim_width;
                self.timeLimitTitleLab.nim_centerY = self.timeLimitView.nim_height * 0.5;
                
                self.timeLimitLab.text = @"已超时";
                [self.timeLimitLab sizeToFit];
                self.timeLimitLab.nim_left = self.timeLimitView.nim_width * 0.5 - 5;
                self.timeLimitLab.nim_centerY = self.timeLimitView.nim_height * 0.5;
                
                addressTop = self.timeLimitView.nim_bottom;
            }
        }
    }else if (self.model.is_dp_wa == 2) {
        if (self.model.status == 3 || self.model.status == 15 || self.model.status == 16) {
            //运单 驳回、已完成、作废时不显示倒计时
        }else {
            if (self.model.countdown > 0) {
                self.timeLimitView.frame = CGRectMake(self.noTitleLab.nim_left, addressTop + 10, self.bgView.nim_width - 2 * self.noTitleLab.nim_left, 33);
                self.timeLimitTitleLab.text = @"距要求到达时间仅剩";
                [self.timeLimitTitleLab sizeToFit];
                self.timeLimitTitleLab.nim_left = self.timeLimitView.nim_width * 0.5 - 15 - self.timeLimitTitleLab.nim_width;
                self.timeLimitTitleLab.nim_centerY = self.timeLimitView.nim_height * 0.5;
                NSInteger days = (int)(self.model.countdown/(3600*24));
                NSInteger hours = (int)((self.model.countdown-days*24*3600)/3600);
                NSInteger minute = (int)(self.model.countdown-days*24*3600-hours*3600)/60;
                NSInteger second = self.model.countdown - days*24*3600 - hours*3600 - minute*60;
                if (days) {
                    self.timeLimitLab.text = [NSString stringWithFormat:@"%ld天%02ld:%02ld:%02ld",(long)days,(long)hours,(long)minute,(long)second];
                }else if (hours) {
                    self.timeLimitLab.text = [NSString stringWithFormat:@"%02ld:%02ld:%02ld",(long)hours,(long)minute,(long)second];
                }else {
                    self.timeLimitLab.text = [NSString stringWithFormat:@"%02ld:%02ld",(long)minute,(long)second];
                }
                [self.timeLimitLab sizeToFit];
                self.timeLimitLab.nim_left = self.timeLimitView.nim_width * 0.5 - 5;
                self.timeLimitLab.nim_centerY = self.timeLimitView.nim_height * 0.5;
                
                addressTop = self.timeLimitView.nim_bottom;
            }else {
                self.timeLimitView.frame = CGRectMake(self.noTitleLab.nim_left, addressTop + 10, self.bgView.nim_width - 2 * self.noTitleLab.nim_left, 33);
                self.timeLimitTitleLab.text = @"距要求到达时间";
                [self.timeLimitTitleLab sizeToFit];
                self.timeLimitTitleLab.nim_left = self.timeLimitView.nim_width * 0.5 - 15 - self.timeLimitTitleLab.nim_width;
                self.timeLimitTitleLab.nim_centerY = self.timeLimitView.nim_height * 0.5;
                
                self.timeLimitLab.text = @"已超时";
                [self.timeLimitLab sizeToFit];
                self.timeLimitLab.nim_left = self.timeLimitView.nim_width * 0.5 - 5;
                self.timeLimitLab.nim_centerY = self.timeLimitView.nim_height * 0.5;
                
                addressTop = self.timeLimitView.nim_bottom;
            }
        }
    }
    
    self.erWeiMaBtn.frame = CGRectZero;
    self.sureDaoDaBtn.frame = CGRectZero;
    self.chaoChuFanWeiBtn.frame = CGRectZero;
    self.yiChangShangBaoBtn.frame = CGRectZero;
    self.dianHuoZhuangCheBtn.frame = CGRectZero;
    self.yiJianZhuangCheBtn.frame = CGRectZero;
    self.waitSureBtn.frame = CGRectZero;
    self.boHuiReasonBtn.frame = CGRectZero;
    
    if (self.model.d_status == 2) {
        //提货出发
        self.bgView.nim_height = addressTop + 60;
        self.sureDaoDaBtn.frame = CGRectMake(self.bgView.nim_width - 10 - 88, self.bgView.nim_height - 15 - 32, 88, 32);
//        self.erWeiMaBtn.frame = CGRectMake(self.sureDaoDaBtn.nim_left - 10 - 74, self.bgView.nim_height - 15 - 32, 74, 32);
    }else if (self.model.d_status == 3) {
        //提货到达
        self.bgView.nim_height = addressTop + 60;
        self.yiJianZhuangCheBtn.frame = CGRectMake(self.bgView.nim_width - 10 - 88, self.bgView.nim_height - 15 - 32, 88, 32);
        self.dianHuoZhuangCheBtn.frame = CGRectMake(self.yiJianZhuangCheBtn.nim_left - 10 - 74, self.bgView.nim_height - 15 - 32, 74, 32);
        self.yiChangShangBaoBtn.frame = CGRectMake(10, self.bgView.nim_height - 15 - 32, 88, 32);
    }else if (self.model.d_status == 4) {
        //装车
        self.bgView.nim_height = addressTop + 60;
        self.waitSureBtn.frame = CGRectMake(self.bgView.nim_width - 10 - 120, self.bgView.nim_height - 15 - 32, 120, 32);
        self.yiChangShangBaoBtn.frame = CGRectMake(10, self.bgView.nim_height - 15 - 32, 88, 32);
    }else if (self.model.d_status == 5) {
        //装车驳回
        self.bgView.nim_height = addressTop + 100;
        self.yiJianZhuangCheBtn.frame = CGRectMake(self.bgView.nim_width - 10 - 88, addressTop + 15, 88, 32);
        self.dianHuoZhuangCheBtn.frame = CGRectMake(self.yiJianZhuangCheBtn.nim_left - 10 - 74, addressTop + 15, 74, 32);
        self.yiChangShangBaoBtn.frame = CGRectMake(10, addressTop + 15, 88, 32);
        self.boHuiReasonBtn.frame = CGRectMake(10, self.yiChangShangBaoBtn.nim_bottom + 10, 88, 32);
    }else if (self.model.d_status == 7) {
        //送货出发
        self.bgView.nim_height = addressTop + 60;
        self.sureDaoDaBtn.frame = CGRectMake(self.bgView.nim_width - 10 - 88, self.bgView.nim_height - 15 - 32, 88, 32);
//        self.erWeiMaBtn.frame = CGRectMake(self.sureDaoDaBtn.nim_left - 10 - 74, self.bgView.nim_height - 15 - 32, 74, 32);
    }else {
        self.bgView.nim_height = addressTop + 10;
    }
    
    self.height = self.bgView.nim_bottom + 10;
}

- (void)configWithTime:(long)downtime {
    if (self.model.is_dp_wa == 1) {
        if (self.model.status == 3 || self.model.status == 9 || self.model.status == 10) {
            //提单 驳回、已完成、作废时不显示倒计时
        }else {
            if (downtime > 0) {
                NSInteger days = (int)(downtime/(3600*24));
                NSInteger hours = (int)((downtime-days*24*3600)/3600);
                NSInteger minute = (int)(downtime-days*24*3600-hours*3600)/60;
                NSInteger second = downtime - days*24*3600 - hours*3600 - minute*60;
                if (days) {
                    self.timeLimitLab.text = [NSString stringWithFormat:@"%ld天%02ld:%02ld:%02ld",(long)days,(long)hours,(long)minute,(long)second];
                }else if (hours) {
                    self.timeLimitLab.text = [NSString stringWithFormat:@"%02ld:%02ld:%02ld",(long)hours,(long)minute,(long)second];
                }else {
                    self.timeLimitLab.text = [NSString stringWithFormat:@"%02ld:%02ld",(long)minute,(long)second];
                }
                [self.timeLimitLab sizeToFit];
                self.timeLimitLab.nim_left = self.timeLimitView.nim_width * 0.5 - 5;
                self.timeLimitLab.nim_centerY = self.timeLimitView.nim_height * 0.5;
            }else {
                self.timeLimitLab.text = @"已超时";
                [self.timeLimitLab sizeToFit];
                self.timeLimitLab.nim_left = self.timeLimitView.nim_width * 0.5 - 5;
                self.timeLimitLab.nim_centerY = self.timeLimitView.nim_height * 0.5;
                if (self.refreshBlock) {
                    self.refreshBlock();
                }
            }
        }
    }else if (self.model.is_dp_wa == 2) {
        if (self.model.status == 3 || self.model.status == 15 || self.model.status == 16) {
            //运单 驳回、已完成、作废时不显示倒计时
        }else {
            if (downtime > 0) {
                NSInteger days = (int)(downtime/(3600*24));
                NSInteger hours = (int)((downtime-days*24*3600)/3600);
                NSInteger minute = (int)(downtime-days*24*3600-hours*3600)/60;
                NSInteger second = downtime - days*24*3600 - hours*3600 - minute*60;
                if (days) {
                    self.timeLimitLab.text = [NSString stringWithFormat:@"%ld天%02ld:%02ld:%02ld",(long)days,(long)hours,(long)minute,(long)second];
                }else if (hours) {
                    self.timeLimitLab.text = [NSString stringWithFormat:@"%02ld:%02ld:%02ld",(long)hours,(long)minute,(long)second];
                }else {
                    self.timeLimitLab.text = [NSString stringWithFormat:@"%02ld:%02ld",(long)minute,(long)second];
                }
                [self.timeLimitLab sizeToFit];
                self.timeLimitLab.nim_left = self.timeLimitView.nim_width * 0.5 - 5;
                self.timeLimitLab.nim_centerY = self.timeLimitView.nim_height * 0.5;
            }else {
                self.timeLimitLab.text = @"已超时";
                [self.timeLimitLab sizeToFit];
                self.timeLimitLab.nim_left = self.timeLimitView.nim_width * 0.5 - 5;
                self.timeLimitLab.nim_centerY = self.timeLimitView.nim_height * 0.5;
                if (self.refreshBlock) {
                    self.refreshBlock();
                }
            }
        }
    }

}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
